#include <iostream>
#include <vector>
#include <unordered_set>

using namespace std;

class Solution {
public:
    vector<int> intersection(vector<int>&& nums1, vector<int>&& nums2) {
        unordered_set<int> result_set;
        unordered_set<int> nums_set(nums1.begin(),nums1.end());

        for(auto &num : nums2)
        {
            // cout << num << "\n";
            if(nums_set.count(num) != 0)
            {
                result_set.insert(num);
            }
        }
        // getchar();

        vector<int> v(result_set.begin(),result_set.end());
        return v;
    }
};

int main(int argc, char const *argv[])
{
    Solution s;
    vector<int> v = s.intersection({1,2,4,5,7},{1,4,6,5,8,7});
    for(auto &num : v)
    {
        cout << num << "\n";
    }
    getchar();
    return 0;
}
